import { _decorator, Component, director, Game, Node } from 'cc';
import { BombUI } from './UI/BombUI';
import { ScoreUI } from './UI/ScoreUI';
import { Player } from './Player';
const { ccclass, property } = _decorator;

@ccclass('GameManager')
export class GameManager extends Component {
    private static instance: GameManager;
    @property
    private bombNumber: number = 0;
    @property(Node)
    bombUI: Node = null;
    @property(ScoreUI)
    scoreUI: ScoreUI = null;

    @property(Node)
    pauseUI: Node = null;
    @property(Node)
    resumeUI: Node = null;
    @property(Player)
    player: Player = null;

    //分数
    private score: number = 0;


    public GetbombNum() {
        return this.bombNumber;
    }

    onPauseButtonClick() {
        //暂停游戏
        director.pause();
        this.player.disableControl();
        if (this.pauseUI.active) {
            this.pauseUI.active = false;
            this.resumeUI.active = true;
        }

    }

    onResumeButtonClick() {
        //恢复游戏
        director.resume();
        this.player.enableController();
        if (this.resumeUI.active) {
            this.pauseUI.active = true;
            this.resumeUI.active = false;
        }
    }


    public AddBomb() {
        console.log('bombUI node =', this.bombUI?.name);
        const bombComp = this.bombUI?.getComponent(BombUI);
        console.log('bombComp =', bombComp);
        console.log("触发了")
        this.bombNumber += 1;
        this.bombUI.getComponent(BombUI).updateUI(this.bombNumber);
    }

    protected onLoad(): void {
        GameManager.instance = this;
    }

    public static getInstance(): GameManager {
        return this.instance;
    }

    public addScore(num: number) {
        this.score += num;
        this.scoreUI.updateUI(this.score);
    }

    protected start(): void {

    }
}


